package com.uyaer.duobao163.vo;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class AwardBagManager {

	private static AwardBagManager instance = new AwardBagManager();

	public static AwardBagManager getInstance() {
		return instance;
	}
	
	public ArrayList<AwardItem> list = null;
	public ArrayList<AwardItem> boxList = null;
	
	public void setData(JSONArray jarr){
		list = new ArrayList<AwardBagManager.AwardItem>();
		boxList = new ArrayList<AwardBagManager.AwardItem>();
		int len = jarr.length();
		for (int i = 0; i < len; i++) {
			try {
				AwardItem item = new AwardItem();
				item.setData(jarr.getJSONObject(i));
				if(item.type == AwardItem.TYPE_AWARD){
					list.add(item);
				}else{
					boxList.add(item);
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}
	
	public class AwardItem{
		public static final int TYPE_BOX = 1;
		public static final int TYPE_AWARD = 2;
		
		public int itemid;
		public int num;
		public int type;
		public AwardItemDescManager.ItemDesc info;
		
		public void setData(JSONObject jobj){
			try {
				this.itemid = jobj.getInt("itemid");
				this.num = jobj.getInt("num");
				this.type = jobj.getInt("type");
				this.info = AwardItemDescManager.getInstance().getItemDescById(jobj.getInt("dictid"));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}
}
